perm filename DISKI.MAC[11,HE] blob sn#549289 filedate 1980-12-08 generic text, type T, neo UTF8
.TITLE DISK I/O TEST PROGRAM

.MCALL ALUN$S,GLUN$S,QIOW$S,EXIT$S,GREG$S
.MCALL FDBDF$,FDAT$A,FDRC$A,FDBK$A,FDOP$A,FINIT$,FSRSZ$,OPEN$R,CLOSE$,READ$

        .BLKW 100                       ;Make some stack space
SPSTRT:

IOSTAT: .WORD 0,0                       ;Status for disk ops

RDSTS:  .WORD 0                         ;Read status block
RDCNT:  .WORD 0

WRSTS:  .WORD 0                         ;Write status block

FDB:    FDBDF$                          ;Make up the disk header info
        FDAT$A  R.FIX,,512.
        FDRC$A  FD.RWM
        FDBK$A  DBUF,512.,,2,IOSTAT
        FDOP$A  2,DATSET,,FO.RD
        FSRSZ$  0

DBUF:   .BLKW 512.

DATSET: .WORD 4,DEVNAM,9.,UIC,6,FILNAM
DEVNAM: .ASCII /DK0:/
UIC:    .ASCII /[200,200]/
FILNAM: .ASCII /FOO.;1/

BUFFER: .BLKB 82.

HIMES:  .ASCII /DISK IMAGE PRINT PROGRAM/
HISIZE = .-HIMES
INIMES:  .ASCII /FINIT DONE/
INISIZ = .-INIMES
OPNMES:  .ASCII /OPEN DONE/
OPNSIZ = .-OPNMES
RDBMES:  .ASCII /READ DONE/
RDBSIZ = .-RDBMES
BYEMES: .ASCII /THAT'S IT/
BYESIZ = .-BYEMES
.EVEN

START:  MOV #SPSTRT,SP                  ;Set up stack???
        ALUN$S #1,#"TI,#0               ;LUN 1 is TI: device
        BCC 1$
        JMP ERROR                       ;Punt if error
1$:     QIOW$S #IO.ATT,#1,#1            ;Attach it
        BCC 2$
        JMP ERROR                       ;Punt if error
2$:     ALUN$S #2,#"DK,#0                ;LUN 2 is DK0:
        BCC 3$
        JMP ERROR                       ;Punt if error
3$:     QIOW$S #IO.WLB,#1,#1,,#WRSTS,,<#HIMES,#HISIZE,#40>      ;Say Hello
        BCC 4$
        JMP ERROR               ;Punt if error
4$:     FINIT$
        BCC 5$
        JMP ERROR
5$:     QIOW$S #IO.WLB,#1,#1,,#WRSTS,,<#INIMES,#INISIZ,#40>   ;Report progress
        OPEN$R #FDB,,,#FD.RWM,,,ERROR
        BCC 6$
        JMP ERROR
6$:     QIOW$S #IO.WLB,#1,#1,,#WRSTS,,<#OPNMES,#OPNSIZ,#40>   ;Report progress
        READ$ #FDB,,,,,,,ERROR
        BCC 7$
        JMP ERROR
7$:     QIOW$S #IO.WLB,#1,#1,,#WRSTS,,<#RDBMES,#RDBSIZ,#40>   ;Report progress

        MOV #0,R0                       ;Byte count of where we are in buffer
        MOV #DBUF,R3
10$:    MOV #BUFFER,R2
        MOV R0,R1                       ;Show buffer address
        JSR PC,OUTNUM
        MOVB #72,(R2)+                  ;Append ": "
        MOVB #40,(R2)+
        MOV (R3),R1                     ;Get next word
        JSR PC,OUTNUM
        MOVB #75,(R2)+                  ;Append "= "
        MOVB #40,(R2)+
        MOVB (R3)+,R1                   ;Show first byte
        BIC #177400,R1
        JSR PC,OUTNUM
        MOVB #40,(R2)+                  ;Append two spaces
        MOVB #40,(R2)+
        MOVB (R3)+,R1                   ;Show second byte
        BIC #177400,R1
        JSR PC,OUTNUM
        SUB #BUFFER,R2  ;Get character count for writing
        QIOW$S #IO.WLB,#1,#1,,#WRSTS,,<#BUFFER,R2,#40>  ;Type it out
        BCS ERROR       ;Punt if error
        ADD #2,R0
        CMP R0,#256.                    ;Only look at the first N words
        BLT 10$

        QIOW$S #IO.WLB,#1,#1,,#WRSTS,,<#BYEMES,#BYESIZ,#60>  ;Say good bye
        BCS ERROR                       ;Punt if error

        EXIT$S ERROR                    ;Go away

        JMP START                       ;?????

ERROR:  IOT                             ;Crash if any errors


;Auxiliary routine to add the octal number in R1 to the buffer R2 points at

OUTNUM: MOV R0,-(SP)    ;We need some free registers
        MOV R1,-(SP)
        MOV R3,-(SP)
        CLR R0
        MOV #6,R3       ;6 digits to print
        ASHC #1,R0      ;Get high order digit
1$:     TST R0          ;Don't print leading zeros
        BNE 2$          ;Found highest order non-zero digit
        ASHC #3,R0      ;Try next
        SOB R3,1$
        INC R3
2$:     ADD #60,R0      ;Convert to ASCII
        MOVB R0,(R2)+   ;Stick it in buffer
        CLR R0
        ASHC #3,R0      ;Move on to next digit
        SOB R3,2$       ;Do them all
        MOV (SP)+,R3    ;Restore registers
        MOV (SP)+,R1
        MOV (SP)+,R0
        RTS PC

.END START